Example: Accessing Named Object ... |
void xyzAppPrint (String printerName, String fileName) throws IOException { try { DSContext ctx = new InitialDSContext(); Printer prt = (Printer) ctx.lookup(printerName); prt.print (new FileInputStream (fileName)); } catch (NamingException e { System.err.println("Unable to locate printer:" + e); } catch (ClassCastException e) { System.err.println(printerName + "not a printer"); } } |